#pragma once

#include <QtWidgets/QWidget>
#include "ui_desktopstreaming.h"
#include "ffmpeg_pusher.h"
#include <QTimerEvent>
#include <QCloseEvent>
#include "RtspPusher.h"

struct vFrame
{
	std::shared_ptr<uint8_t> data; 
	int frame_size; 
	//uint8_t type;
	int64_t timestamp;
};

//using namespace jlh;
class DesktopStreaming : public QWidget
{
    Q_OBJECT

public:
    explicit DesktopStreaming(QWidget *parent = Q_NULLPTR);
	virtual ~DesktopStreaming();

	void PushVideo(std::shared_ptr<uint8_t>& data, int frame_size, int64_t timestamp);
	void PushAudio(std::shared_ptr<uint8_t>& data, int frame_size, int64_t timestamp);

public slots:
	void StartLive();
	void StopLive();
	void slotNewFrame();
	void slotNewAudio();

protected:
	void timerEvent(QTimerEvent* ev) override;
	void closeEvent(QCloseEvent* ev) override;

private:
	void resetRefreshTimer();
	void refreshVideo();

	void StartLive_();
	void StopLive_();

signals:
	void newFrame();
	void newAudio();

private:
    Ui::DesktopStreamingClass ui;

	ffPusherState fState;
	int ui_refresh_timer_id_ = -1;

	//std::shared_ptr<jlh::RtspPusher> rtsp_pusher_;

	std::mutex mutex_;
	std::list<vFrame> vframes_;
	std::list<vFrame> aframes_;

	jlh::MediaSessionId media_session_id_ = 0;
};
